import request from '@/api/request'
import { AxiosPromise } from 'axios'
import { TreeKey } from 'element-plus/es/components/tree/src/tree.type.mjs'

enum API {
    BASE_URL="/system/roles/",
    LIST_URL = "/system/roles/list",
    PAGE_URL = "/system/roles/page",
    ADD_URL = "/system/roles",
    UPDATE_URL = "/system/roles",
    DELETE_URL = "/system/roles",
    BATCH_DELETE_URL = "/system/roles/batch-delete",

}

export const assignMenusApi = (roleId:string,menuIds:TreeKey[])=>{
    return request.put<any>(API.BASE_URL+"assign-menus/"+roleId,menuIds)
}

export const fetchMenusOfRoleApi = (id:string)=>{
    return request.get<any>(API.BASE_URL+id+"/menus")
}

export const fetchRolesListApi = ():AxiosPromise<any> => {
    return request.get<any>(API.LIST_URL)
}

export const fetchRolesPageApi = (current:number,size:number,data:any):AxiosPromise<any> => {
    return request.post<any>(API.PAGE_URL+'/'+current+'/'+size,data)
}

export const createRoleApi = (data:any):AxiosPromise<any> => {
    return request.post<any>(API.ADD_URL,data)
}

export const updateRoleApi = (data:any):AxiosPromise<any> => {
    return request.put<any>(API.UPDATE_URL,data)
}

export const deleteRoleByIdApi = (id:string):AxiosPromise<any> => {
    return request.delete<any>(API.DELETE_URL+'/'+id)
}

export const batchDeleteRolesApi = (ids:string[]):AxiosPromise<any> => {
    return request.delete<any>(API.DELETE_URL,{params:ids})
}